<?php

namespace IDock\Insurance\TAIC\Request;

use IDock\Insurance\TAIC\Response\VehicleModelResponse;
use IDock\Visitor\VehicleModelVisitor;

class VehicleModelRequest extends AllTAICRequest
{
    protected $route = 'access/car/queryCarModel.mvc';

    protected $response = VehicleModelResponse::class;

    protected $urlTip = '车型查询';

    /**
     * @var  VehicleModelVisitor $visitor
     */
    protected $visitor;

    public $switch = false;

    public function generate(): array
    {
        if ($this->switch) {
            preg_match('/\w+/',$this->visitor->vehicleModel,$matches);

            if ($matches[0] ?? ''){
                if ($matches[0]) {
                    $this->visitor->vehicleModel = $matches[0];
                }
            } else {
                $this->visitor->vehicleModel = preg_replace('/[\x{4e00}-\x{9fa5}\-]/u', '', $this->visitor->vehicleModel);
            }
        }

        $this->setTradeNo();

        return [
            'cityCode' => $this->visitor->argc['cityCode'] ?? '',
            'brandName' => $this->visitor->vehicleModel,
            'enginNo' => $this->visitor->engineNo,
            'enrollDate' => $this->visitor->firstRegisterDate,
            'startDate' => date('Y-m-d', strtotime('+1 day')),
            'frameNo' => $this->visitor->vin,
            'licenseNo' => $this->visitor->licenseNo,
            'licenseType' => '',
            'page' => '',
            'rows' => '',
            'purchaseDate' => '',
            'salesNetworkCode' => '',
        ];
    }
}
